package wypozyczalnia.domain;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

@Entity
@Table(name = "person")
public class Person extends BaseEntity {

	/**
	 * 
	 */
	private static final int NORMAL_LENGTH = 255;
	private static final int MAX_LENGTH = 4000;
	private static final long serialVersionUID = 1L;

	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	@Column(updatable = false, name = "PERSON_ID")
	private Integer idPerson;

	@Column(length = 255, nullable = false)
	private String name;

	@Column(length = 255, nullable = false)
	private String surname;

	@Column(length = 4000, nullable = true)
	private String description;

	@Column(nullable = false)
	@Temporal(TemporalType.TIMESTAMP)
	private Date birthDate;

	@Column(length = 255, nullable = true)
	private String nationality;
	
	@OneToMany(fetch = FetchType.LAZY, mappedBy = "user")
	private List<Hire> hires;

	@OneToMany(cascade = { javax.persistence.CascadeType.ALL }, mappedBy = "person")
	private List<Photo> photos;

	@ManyToMany(fetch=FetchType.LAZY)
	@JoinTable(name="movie_person", joinColumns={@javax.persistence.JoinColumn(name="MOVIE_ID")}, inverseJoinColumns={@javax.persistence.JoinColumn(name="PERSON_ID")})
	private List<Movie> movie;

	public Person() {
	}

	public Person(String name, String surname, String description,
			Date birthDate, String nationality, List<Photo> photos,
			List<Movie> movies) {
		this.name = name;
		this.surname = surname;
		this.description = description;
		this.birthDate = birthDate;
		this.nationality = nationality;
		this.photos = photos;
		this.movie = movies;
	}

	public Person(String name, String surname, String description,
			Date birthDate, String nationality) {
		this.name = name;
		this.surname = surname;
		this.description = description;
		this.birthDate = birthDate;
		this.nationality = nationality;
		this.photos = new ArrayList();
		this.movie = new ArrayList();
	}

	public String getName() {
		return this.name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getSurname() {
		return this.surname;
	}

	public void setSurname(String surname) {
		this.surname = surname;
	}

	public String getDescription() {
		return this.description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public Date getBirthDate() {
		return this.birthDate;
	}

	public void setBirthDate(Date birthDate) {
		this.birthDate = birthDate;
	}

	public String getNationality() {
		return this.nationality;
	}

	public void setNationality(String nationality) {
		this.nationality = nationality;
	}

	public List<Photo> getPhotos() {
		return this.photos;
	}

	public void setPhotos(List<Photo> photos) {
		this.photos = photos;
	}

	public List<Movie> getMovie() {
		return this.movie;
	}

	public void setMovie(List<Movie> movies) {
		this.movie = movies;
	}

	public Integer getIdPerson() {
		return this.idPerson;
	}

	public void setIdPerson(Integer idPerson) {
		this.idPerson = idPerson;
	}

	public List<Hire> getHires() {
		return hires;
	}

	public void setHires(List<Hire> hires) {
		this.hires = hires;
	}

}
